<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@page import="org.springframework.web.context.WebApplicationContext"%>
<%@page import="org.springframework.web.context.support.WebApplicationContextUtils"%>
<%@page import="db.Project"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="db.ProjectDAO"%>
<%@page import="db.PurreqDAO" %>
<%@page import="db.UserDAO" %>
<%@page import="db.User"%>
<%@page import="org.json.JSONObject"%>
<%@page import="db.TmppurDAO"%>
<%@page import="db.Tmppur"%>
<%@page import="db.Fororder"%>
<%@page import="db.FororderDAO"%>
<%@ include file="/jsp/common/utility/volti.jsp" %>
<%@ include file="/jsp/common/utility/logined.jsp" %>
<%
	response.setHeader("Pragma", "No-cache");
	response.setHeader("Cache-Control", "no-cache");
	response.setDateHeader("Expires", 0);
	response.setContentType("application/x-javascript");
	out.clear();
	request.setCharacterEncoding("utf-8");
	String callback = request.getParameter("callback");
	String jsonString = request.getParameter("jsonString");
	JSONObject requestJSONobject = new JSONObject(jsonString);
	JSONObject responseJSONObject = new JSONObject();
	int type = requestJSONobject.optInt("type");
	String socode = requestJSONobject.optString("socode");
	//System.out.println("type=====>"+type+"======>"+socode);
	
	WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
	TmppurDAO tmppurDAO = (TmppurDAO)ctx.getBean("TmppurDAO");
	FororderDAO fororderDAO = (FororderDAO)ctx.getBean("FororderDAO");
	Map map =new HashMap();
	if(type==0){
		List where = new ArrayList();
		where.add(new Object[]{"eq", "state", 1});
		int tid = 0;
		tid = (Integer)session.getAttribute("tid");
		if(tid!=0){
			where.add(new Object[]{"eq", "teamId",tid});
		}
		Object[][] ob = new Object[][]{};
		List listob = new ArrayList();
		if(socode!=null ||!"".equals(socode)){
			listob.add(new Object[]{"like","tmpCode",socode});
			listob.add(new Object[]{"like","pr.name",socode});
			where.add(new Object[]{"or","",listob});
		}
			map = tmppurDAO.getTmppur(0,999,
				new String[][]{new String[]{"desc","date"}},
				where,
				new String[][]{new String[]{"","id"},new String[]{"","tmpCode"},new String[]{"","pr.name"}}
				,new String[]{"purreq","project","reqUser"});
	}
	if(type==1){
		List where = new ArrayList();
		int tid = 0;
		tid = (Integer)session.getAttribute("tid");
		where.add(new Object[]{"eq", "isConvert",0});
		if(tid!=0){
			where.add(new Object[]{"eq", "teamId",tid});
		}
		Object[][] ob = new Object[][]{};
		List listob = new ArrayList();
		if(socode!=null ||!"".equals(socode)){
			listob.add(new Object[]{"like","proName",socode});
			listob.add(new Object[]{"like","orderCode",socode});
			where.add(new Object[]{"or","",listob});
		}
		map = fororderDAO.getFororder(0,999,
				new String[][]{new String[]{"desc","date"}},
				where,
				new String[][]{new String[]{"","id"},new String[]{"","orderCode"},new String[]{"","proName"}}
				,new String[]{"","",""});
	}
	
	SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
	String rdate = sdf.format(new Date());
	
	responseJSONObject.put("map", map);
	responseJSONObject.put("success", true);
	responseJSONObject.put("message", "您的删除操作已成功!");
	String result = callback + "('" + responseJSONObject.toString() + "');";
	out.write(result);
%>
<%!
	
%>